package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.HouseCollection;
import com.stylefeng.guns.modular.system.service.IHouseCollectionService;

/**
 * 用户收藏控制器
 *
 * @author leequn
 * @Date 2018-08-02 23:39:38
 */
@Controller
@RequestMapping("/houseCollection")
public class HouseCollectionController extends BaseController {

    private String PREFIX = "/system/houseCollection/";

    @Autowired
    private IHouseCollectionService houseCollectionService;

    /**
     * 跳转到用户收藏首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "houseCollection.html";
    }

    /**
     * 跳转到添加用户收藏
     */
    @RequestMapping("/houseCollection_add")
    public String houseCollectionAdd() {
        return PREFIX + "houseCollection_add.html";
    }

    /**
     * 跳转到修改用户收藏
     */
    @RequestMapping("/houseCollection_update/{houseCollectionId}")
    public String houseCollectionUpdate(@PathVariable Integer houseCollectionId, Model model) {
        HouseCollection houseCollection = houseCollectionService.selectById(houseCollectionId);
        model.addAttribute("item",houseCollection);
        LogObjectHolder.me().set(houseCollection);
        return PREFIX + "houseCollection_edit.html";
    }

    /**
     * 获取用户收藏列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return houseCollectionService.selectList(null);
    }

    /**
     * 新增用户收藏
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HouseCollection houseCollection) {
        houseCollectionService.insert(houseCollection);
        return SUCCESS_TIP;
    }

    /**
     * 删除用户收藏
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer houseCollectionId) {
        houseCollectionService.deleteById(houseCollectionId);
        return SUCCESS_TIP;
    }

    /**
     * 修改用户收藏
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HouseCollection houseCollection) {
        houseCollectionService.updateById(houseCollection);
        return SUCCESS_TIP;
    }

    /**
     * 用户收藏详情
     */
    @RequestMapping(value = "/detail/{houseCollectionId}")
    @ResponseBody
    public Object detail(@PathVariable("houseCollectionId") Integer houseCollectionId) {
        return houseCollectionService.selectById(houseCollectionId);
    }
}
